GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 418fbb...00be91 )
by Florian
59s
created

uploadgpx.js ➔ handleGpxFiles   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 3
c 2
b 0
f 1
nc 2
nop 1
dl 0
loc 52
rs 9.4929

1 Function

Rating   Name   Duplication   Size   Complexity  
B uploadgpx.js ➔ ... ➔ reader.onloadend 0 32 4

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/*jslint
2
  regexp: true
3
  indent: 4
4
*/
5
6
/*global
7
  $, google, FileReader, DOMParser,
8
  Markers, showAlert, mytrans
9
*/
10
11
12
function parseWpt(wpt, default_name) {
13
    'use strict';
14
15
    var el, i,
16
        name = '',
17
        radius = 0;
18
19
    el = wpt.getElementsByTagName('name');
20
    if (el.length > 0) {
21
        name = el[0].textContent;
22
    }
23
    name = name.replace(/[^A-Za-z0-9_\-]/gi, '');
24
    if (name === '') {
25
        name = default_name;
26
    }
27
28
    el = wpt.getElementsByTagName('*');
29
    for (i = 0; i < el.length; i = i + 1) {
30
        if (el[i].tagName === 'wptx1:Proximity') {
31
            radius = parseInt(el[i].textContent, 10);
32
            break;
33
        }
34
    }
35
36
    return {
37
        name: name,
38
        coords: new google.maps.LatLng(wpt.getAttribute('lat'), wpt.getAttribute('lon')),
39
        radius: radius
40
    };
41
}
42
43
44
function handleGpxFiles(files) {
45
    'use strict';
46
47
    if (!files || !files.length) {
48
        showAlert(
49
            mytrans("uploadgpx.error"),
50
            mytrans("uploadgpx.error_no_files")
51
        );
52
        return;
53
    }
54
55
    var reader = new FileReader(),
56
        parser = new DOMParser();
57
58
    reader.readAsText(files[0]);
59
    reader.onloadend = function () {
60
        var xml = parser.parseFromString(reader.result, "text/xml"),
61
            wpts,
62
            wpt,
63
            i;
64
        if (!xml) {
65
            showAlert(
66
                mytrans("uploadgpx.error"),
67
                mytrans("uploadgpx.error_bad_xml")
68
            );
69
            return;
70
        }
71
72
        wpts = xml.getElementsByTagName('wpt');
73
        for (i = 0; i < wpts.length; i = i + 1) {
74
            wpt = parseWpt(wpts[i], 'wpt_' + i);
75
            if (!Markers.newMarker(wpt.coords, -1, wpt.radius, wpt.name)) {
76
                showAlert(
77
                    mytrans("uploadgpx.error"),
78
                    mytrans("uploadgpx.error_failed_after").replace(/%1/, i)
79
                );
80
                return;
81
            }
82
        }
83
        
84
        showAlert(
85
            mytrans("uploadgpx.info"),
86
            mytrans("uploadgpx.msg_created_markers").replace(/%1/, wpts.length)
87
        );
88
89
        // TODO pan to center of imported markers, adjust zoom
90
    };
91
92
    // reset file input
93
    $('#buttonUploadGPXinput').wrap('<form>').closest('form').get(0).reset();
94
    $('#buttonUploadGPXinput').unwrap();
95
}
96